package operation;
import book.Book;
import book.BookList;
import java.util.Scanner;
public class AddOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        int size=bookList.getUseSize();
        if(size==bookList.getBooks().length){
            System.out.println("书架已满，无法添加图书");
            return;
        }
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入添加书的书名");
        String name=scanner.nextLine();
        System.out.println("请输入添加书的作者");
        String author=scanner.nextLine();
        System.out.println("请输入添加书的类型");
        String type=scanner.nextLine();
        System.out.println("请输入添加书的价格");
        int price=scanner.nextInt();
        Book book = new Book(name, author, price, type);
        for (int i = 0; i < size; i++) {
            if(bookList.getbook(i).getName().equals(name)){
                System.out.println("该书已有，不再存入");
                return;
            }
        }
        bookList.setbook(size,book);
        bookList.setUseSize(size+1);
    }

}
